package com.honey.solr.daosupport.method;

import com.honey.compilation.java.Method;
import com.honey.compilation.java.Parameter;
import com.honey.generator.java.AbstractClassName;
import com.honey.solr.SolrConstant;
import com.honey.solr.SolrFactory;

public class Query3Method extends AbstractClassName {
	
	private SolrFactory solrFactory = null;
	
	public Query3Method(SolrFactory solrFactory ){
		this.solrFactory =solrFactory;
	}
	
	public Method createMethod(){
		Method answer = new Method("query");
		Parameter parameter = new Parameter(SolrConstant.SOLR_QUERY,"query");
		answer.addParameter(parameter) ;
		
		answer.setReturnType(SolrConstant.QUERY_RESPONSE);
		answer.addBodyLine("QueryResponse answer = null ");
		
		answer.addException(SolrConstant.SOLR_SERVER_EXCEPTION);
		boolean bool = solrFactory.getSolrPlugin().getQueryForPage() != null ;
		
		
		answer.addBodyLine("addQueryParameter( query"+( bool?",null":"" )+" )");
		
		
		answer.addBodyLine("answer = "+SolrConstant.SOLR_SERVER_FIELD_NAME+".query(query)") ;
		answer.addBodyLine("return answer") ;
		return answer;
	}
}
